package com.bigdatan.b2c.upload.glass;

import com.alibaba.fastjson.JSON;
import com.aliyun.oss.OSSClient;
import com.aliyun.oss.model.PutObjectResult;

import java.io.File;

/**
 * Created by shangdong on 17/5/26.
 */
public class AliYunUpload {

    public static void main(String[] args) {
        // endpoint以杭州为例，其它region请按实际情况填写
        //oss-cn-shenzhen.aliyuncs.com	oss-cn-shenzhen-internal.aliyuncs.com
        String endpoint = "oss-cn-shenzhen.aliyuncs.com";
// accessKey请登录https://ak-console.aliyun.com/#/查看
        String accessKeyId = "LTAIHRZWfjPqwmuu";
        String accessKeySecret = "u6MxT7CHlmxRKcBUkuiTSJIHosM9S6";
         String bucketName = "glass-pic-info";


// 创建OSSClient实例
        OSSClient ossClient = new OSSClient(endpoint, accessKeyId, accessKeySecret);
        File file = new File("/Users/shangdong/Desktop/1.jpg");
        String md5 = SimpleImageInfo.getMD5(file);
//        String content = "Hello OSS";
        PutObjectResult putObjectResult = ossClient.putObject(bucketName, md5, file);
        System.out.println(JSON.toJSONString(putObjectResult));

// 使用访问OSS

// 关闭ossClient
        ossClient.shutdown();
    }
}
